home *** CD-ROM | disk | FTP | other *** search
/ Windows Expert / Windows Expert.iso / others / ole_101.zip / PATRON.ZIP / OLELOAD.C < prev    next >
C/C++ Source or Header  |  1992-04-13  |  6KB  |  230 lines

  1. /*
  2.  * OLELOAD.C
  3.  *
  4.  * Functions to handle updating links on File Open.
  5.  *
  6.  * Copyright(c) Microsoft Corp. 1992 All Rights Reserved
  7.  */
  8.  
  9.  
  10. #include <windows.h>
  11. #include <ole.h>
  12. #include "register.h"
  13. #include "oclient.h"
  14.  
  15.  
  16.  
  17. /*
  18.  * FObjectAutoLinkUpdate
  19.  *
  20.  * Purpose:
  21.  *  Checks if the object link is automatic and if so, update it if the
  22.  *  server is open, waiting as necessary.
  23.  *
  24.  * Parameters:
  25.  *  pDoc            LPDOCUMENT containing OLE information.
  26.  *  pObj            LPOBJECT to the object in question.
  27.  *
  28.  * Return Value:
  29.  *  BOOL            TRUE if the object was updated, FALSE if the object
  30.  *                  is a manual link or the server was not open.
  31.  */
  32.  
  33. BOOL FAR PASCAL FObjectAutoLinkUpdate(LPDOCUMENT pDoc, LPOBJECT pObj)
  34.     {
  35.     OLESTATUS       os;
  36.  
  37.     if (NULL==pObj)
  38.         return FALSE;
  39.  
  40.     //Check for an automatic link.
  41.     if (oleupdate_always!=pObj->dwLink)
  42.         return FALSE;
  43.  
  44.     /*
  45.      * Check if the server is open for this object with OleQueryOpen.  If
  46.      * it is, then call OleUpdate and wait for the update to complete
  47.      * before moving on.
  48.      */
  49.     os=OleQueryOpen(pObj->pObj);
  50.  
  51.     if (OLE_OK!=os)
  52.         return FALSE;
  53.  
  54.     os=OleUpdate(pObj->pObj);
  55.  
  56.     return (OLE_OK==OsError(os, pDoc, pObj, TRUE));
  57.     }
  58.  
  59.  
  60.  
  61.  
  62.  
  63.  
  64. /*
  65.  * FOLELinksUpdate
  66.  *
  67.  * Purpose:
  68.  *  Checks if the recently loaded file had objects requiring update.
  69.  *  If so, then prompt the user to update links, and if they answer
  70.  *  Yes, then call OleUpdate for all linked objects.
  71.  *
  72.  *  If any of the links cannot be updated, then we prompt the user and
  73.  *  fall into the Links dialog if they so choose.
  74.  *
  75.  * Parameters:
  76.  *  hWnd            HWND parent of dialogs.
  77.  *  hInst           HANDLE to the application instance.
  78.  *  pDoc            LPDOCUMENT identifying the list of objects we have.
  79.  *
  80.  * Return Value:
  81.  *  BOOL            TRUE if all objects could be updated or if the user
  82.  *                  used the Links dialog.  FALSE if there are still
  83.  *                  non-updated links.
  84.  */
  85.  
  86. BOOL FAR PASCAL FOLELinksUpdate(HWND hWnd, HANDLE hInst, LPDOCUMENT pDoc)
  87.     {
  88.     FARPROC         lpfn;
  89.     WORD            wTemp;
  90.  
  91.     //Check if we have any links to update
  92.     if (0==pDoc->cLinks)
  93.         return TRUE;
  94.  
  95.     //Ask the user.
  96.     wTemp=MessageBox(hWnd, PSZOLE(IDS_UPDATELINKS0), PSZOLE(IDS_UPDATEMSG),
  97.                      MB_YESNO | MB_ICONEXCLAMATION);
  98.  
  99.  
  100.     if (IDYES!=wTemp)
  101.         return FALSE;
  102.  
  103.     pDoc->cLinks=0;
  104.     FObjectsEnumerate(pDoc, FEnumUpdate, 0L);
  105.     FOLEReleaseWait(TRUE, pDoc, NULL);
  106.  
  107.  
  108.     /*
  109.      * If pDoc->cLinks!=0 now, then we had some unavailable links
  110.      * which we now need to let the user update, if desired.
  111.      */
  112.     if (0==pDoc->cLinks)
  113.         return TRUE;
  114.  
  115.     //Show the dialog allowing transit to the Links... dialog.
  116.     lpfn=MakeProcInstance(LinksUnavailableProc, hInst);
  117.     wTemp=DialogBox(hInst, MAKEINTRESOURCE(IDD_BADLINKS), hWnd, lpfn);
  118.     FreeProcInstance(lpfn);
  119.  
  120.     if (0!=wTemp)
  121.         return FALSE;
  122.  
  123.     //Go do the links dialog
  124.     return FOLELinksEdit(hWnd, hInst, pDoc);
  125.     }
  126.  
  127.  
  128.  
  129.  
  130. /*
  131.  * FEnumUpdate
  132.  *
  133.  * Purpose:
  134.  *  For each enumerated object that is linked call OleUpdate.  We expect
  135.  *  to be used from FOLELinksUpdate which is used when opening a document.
  136.  *
  137.  * Parameters:
  138.  *  pDoc            LPDOCUMENT identifying the owner of all objects.
  139.  *  pObj            LPOBJECT identifying the current object.
  140.  *  dw              DWORD for extra data, unused.
  141.  *
  142.  * Return Value:
  143.  *  BOOL            TRUE--we want to enumerate everything.
  144.  */
  145.  
  146. BOOL FAR PASCAL FEnumUpdate(LPDOCUMENT pDoc, LPOBJECT pObj, DWORD dw)
  147.     {
  148.     OLESTATUS       os;
  149.  
  150.     pDoc->cWait=0;
  151.  
  152.     if (OT_LINK==pObj->dwType)
  153.         {
  154.         os=OleUpdate(pObj->pObj);
  155.  
  156.         /*
  157.          * Wait for this object now since we need to know if it succeeded
  158.          * or not after the object is released.
  159.          */
  160.         if (OLE_OK!=OsError(os, pDoc, pObj, TRUE))
  161.             {
  162.             //Mark this link as Unavailable.
  163.             pObj->dwLink=OLEUPDATE_UNAVAILABLE;
  164.             pDoc->cLinks++;
  165.             }
  166.         }
  167.  
  168.  
  169.     return TRUE;
  170.     }
  171.  
  172.  
  173.  
  174.  
  175. /*
  176.  * LinksUnavailableProc
  177.  *
  178.  * Purpose:
  179.  *  Dialog procedure for the dialog to inform the user that some
  180.  *  linked files were unavailable, giving the user the option to
  181.  *  change the links with the Links dialog.
  182.  *
  183.  *  The only reason we have this dialog is to enable us to use a
  184.  *  system icon and a non-standard button.  Otherwise we could use
  185.  *  a message box.
  186.  *
  187.  *  On return from this function, the caller should check the return
  188.  *  value.  If it's 0, then the caller should display the Links
  189.  *  dialog.
  190.  *
  191.  * Parameters:
  192.  *  The standard.
  193.  *
  194.  * Return Value:
  195.  *  The value to be returned through the DialogBox call that
  196.  *  created the dialog.
  197.  */
  198.  
  199. BOOL FAR PASCAL LinksUnavailableProc(HWND hDlg, WORD iMsg, WORD wParam, LONG lParam)
  200.     {
  201.     HANDLE      hIcon;
  202.  
  203.     switch (iMsg)
  204.         {
  205.         case WM_INITDIALOG:
  206.             //No need to free the previous icon since there wasn't one
  207.             hIcon=LoadIcon(NULL, MAKEINTRESOURCE(IDI_EXCLAMATION));
  208.  
  209.             //Note:  This is Windows 3.1 specific.  Use SetDlgItemText in 3.0
  210.             SendDlgItemMessage(hDlg, ID_ICONEX, STM_SETICON, hIcon, 0L);
  211.             return TRUE;
  212.  
  213.         case WM_COMMAND:
  214.             switch (wParam)
  215.                 {
  216.                 //Note that we do not want to delete the system icon.
  217.  
  218.                 case ID_LINKS:
  219.                     EndDialog(hDlg, FALSE);
  220.                     break;
  221.  
  222.                 case IDOK:
  223.                     EndDialog(hDlg, TRUE);
  224.                     break;
  225.                 }
  226.             break;
  227.         }
  228.     return FALSE;
  229.     }
  230.